var _n61;
var cc__extends = __extends;
var cc__decorate = __decorate;
var cc__importDefault = __importDefault;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $1$Loader = require("Loader");
var s = cc__importDefault($1$Loader);
var $1$yyComponent = require("yyComponent");
var c = cc__importDefault($1$yyComponent);
var $GameEventType = require("GameEventType");
var $zqcc_OverallSystem = require("zqcc_OverallSystem");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_homeRankItem = function (t) {
  function _ctor() {
    // 调用 t 函数，如果返回 null，则使用 this
    const e = null !== t && t.apply(this, arguments) || this;

    // 设置对象的初始属性
    e.label1 = null;
    e.label2 = null;
    e.label3 = null;
    e.diquName = null;
    e.itemID = -1;           // 设置 itemID 为 -1
    e.qiqiuNode = null;
    e.city = null;
    e.pifu = 0;              // 默认值为0
    e.shengming = "";        // 初始化为字符串

    // 返回对象
    return e;
  }
  cc__extends(_ctor, t);
  _ctor.prototype.start = function () {
    const t = this;

    // 定义加载图片的函数
    const loadImage = function (_e2) {
      const sizes = [16, 10, 16, 10, 16, 16];
      const randomIndex = Math.floor(Math.random() * sizes.length);
      const type = ["biaoqing", "cunse", "biaoqing", "cunse", "biaoqing", "suipian"][randomIndex];
      const selectedSize = sizes[randomIndex];
      const randomNumber = Math.floor(Math.random() * selectedSize) + 1;

      _e2.active = false; // 隐藏节点

      s.default.loadBundleRes("home", `rank/${type}/${type}${randomNumber}`, function (resource) {
        if (t && t.node) {
          const spriteComponent = _e2.getComponent(cc.Sprite);
          const resourceWidth = resource.width;
          const resourceHeight = resource.height;
          _e2.width = resourceWidth;
          _e2.height = resourceHeight;
          spriteComponent.spriteFrame = new cc.SpriteFrame(resource);
          _e2.active = true;
          t.scheduleOnce(() => {
            _e2.getComponent(cc.Animation).play();
          }, Math.random() + 0.2); // 随机延迟播放动画
        }
      });
    };

    // 遍历每个子节点并加载图像
    const childNodes = this.qiqiuNode.children;
    for (let index = 0; index < childNodes.length; index++) {
      loadImage(childNodes[index]);
    }

    // 监听事件并更新排名项
    this.on($GameEventType.EventType.DirectorEvent.pifugenghuan, this.updateRankItem, this);
    this.updateRankItem();
  };
  _ctor.prototype.updateRankItem = function () {
    cc.log("更新数据");
    this.city = $zqcc_OverallSystem.sers().userSrv.getUserData().city;
    this.pifu = $zqcc_OverallSystem.sers().userSrv.getQiqiupifu().index;
    this.wodepifu();
  };
  _ctor.prototype.updateContent = function (t, e) {
    this.itemID = e; // 设置项ID
    const rankInfo = t.cityRankInfo[e]; // 获取城市排名信息

    if (rankInfo) {
      // 更新标签信息
      this.label1.string = `第${this.numberToChinese(e + 1)}名`;
      this.label2.string = rankInfo.university;

      const childrenNodes = this.node.children;

      // 控制子节点的显示/隐藏
      childrenNodes.forEach((child, index) => {
        child.active = (index === this.itemID);
      });

      // 更新城市名称
      this.renewSp(rankInfo.cityName);
    }
  };
  _ctor.prototype.numberToChinese = function (t) {
    if (t === 10) {
      return "十";
    }
    if (t === 1) {
      return "一";
    }

    const numWords = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
    const units = ["", "十", "百", "千", "万"];
    let result = "";
    const strNum = t.toString();

    for (let r = 0; r < strNum.length; r++) {
      const digit = parseInt(strNum.charAt(r));
      const unit = units[strNum.length - r - 1];

      if (digit === 0) {
        // 只在最后一个字符不是“零”时添加
        if (result.charAt(result.length - 1) !== "零") {
          result += "零";
        }
      } else {
        result += numWords[digit] + unit;
      }
    }

    // 移除结果开头的“一”或处理“百”、“千”前的逻辑
    if (result.startsWith("一")) {
      result = result.substr(1);
    } else if (["百", "千"].includes(result.charAt(0))) {
      result = "一" + result;
    }

    return result;
  };
  _ctor.prototype.renewSp = function (t) {
    this.diquName.string = t + "";
    this.shengming = t;
    this.wodepifu();
  };
  _ctor.prototype.wodepifu = function () {
    const t = this; // 保持对当前上下文的引用
    const e = this.city; // 获取城市
    const o = this.pifu; // 获取皮肤

    this.node.getChildByName("zheli").active = false; // 隐藏 zheli 节点

    // 检查条件
    if (e && e.cityName === this.shengming && o > 0) {
      cc.log("在这" + o); // 打印当前皮肤值

      const lastChild = this.qiqiuNode.children[this.qiqiuNode.childrenCount - 1]; // 获取最后一个子节点

      // 加载资源
      s.default.loadBundleRes(`home/rank/biaoqing/biaoqing${o}`, function (resource) {
        if (t && t.node) {
          const spriteComponent = lastChild.getComponent(cc.Sprite); // 获取精灵组件
          const resourceWidth = resource.width;
          const resourceHeight = resource.height;

          // 设置节点的尺寸及精灵帧
          lastChild.width = resourceWidth;
          lastChild.height = resourceHeight;
          spriteComponent.spriteFrame = new cc.SpriteFrame(resource);
          lastChild.active = true; // 激活节点

          // 显示 zheli 节点
          t.node.getChildByName("zheli").active = true;
        }
      });
    }
  };
  cc__decorate([ccp_property(cc.Label)], _ctor.prototype, "label1", undefined);
  cc__decorate([ccp_property(cc.Label)], _ctor.prototype, "label2", undefined);
  cc__decorate([ccp_property(cc.Label)], _ctor.prototype, "label3", undefined);
  cc__decorate([ccp_property(cc.Label)], _ctor.prototype, "diquName", undefined);
  cc__decorate([ccp_property(cc.Node)], _ctor.prototype, "qiqiuNode", undefined);
  return cc__decorate([ccp_ccclass], _ctor);
}(c.default);
exports.default = def_homeRankItem;